<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="cake.Cake" %>
<%@ page import="java.util.List" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="cake.CakeDao" %>
<%@ page import="cake.CakeDaoImpl" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false" %>
<html>
<head>
    <title>管理员页面</title>
</head>
<body>
<div style="text-align: center">
    <div>
        <h1>商品管理</h1>
        <br>
        <br>
        <br>
        <br>

    </div>
    <div style="text-align: center;position: center ;margin: auto">
        <a href="add.jsp">新增商品</a>
        <br>
        <br>
        <table width="600" border="1" cellpadding="0" align="center">
            <tr>
                <th>编号</th>
                <th>商品名称</th>
                <th>商品详细</th>
                <th>价格</th>
                <th>库存</th>
                <th>操作</th>
            </tr>
            <%
                String driverClass = "com.mysql.cj.jdbc.Driver";
                String url = "jdbc:mysql://localhost:3306/cart?serverTimezone=Asia/Shanghai";
                String user = "root";
                String password = "111111";
                Connection conn;
                try {
                    Class.forName(driverClass);
                    conn = DriverManager.getConnection(url, user, password);
                    Statement stmt = conn.createStatement();
                    String sql = "select * from shop order by id";
                    ResultSet rs = stmt.executeQuery(sql);
                    while (rs.next()) {
            %>
            <%--            DetailServlet?shop=${Cake.shop}   --%>
            <tr align="center">
                <td><%=rs.getString("id")%>
                </td>
                <td><%=rs.getString("shop")%>
                </td>
                <td><%=rs.getString("detail")%>
                </td>
                <td><%=rs.getString("price")%>
                </td>
                <td><%=rs.getString("num")%>
                </td>
                <td><a href="shopDeleteServlet?id=<%=rs.getString("id") %>">删除商品</a></td>

            </tr>
            <%
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            %>
        </table>
    </div>
</div>

</body>
</html>